/**
 * Created by админ on 26.06.14.
 */

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import static sun.misc.Version.println;

public class Main {

    public static void main(String[] args) {
        final List ml = new List();


        JFrame frame = new JFrame("Test frame");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JMenu newMenu = new  JMenu("New");
        final JTextField textField1 = new JTextField(20);
        final JTextField textField2 = new JTextField();
        final Font font = new Font("Verdana", Font.PLAIN, 11);

        JMenuBar menuBar = new JMenuBar();
        frame.add(textField1);
        textField1.setEditable(false);
        JMenu fileMenu = new JMenu("List");
        fileMenu.setFont(font);
        textField1.setFont(font);
        textField2.setFont(font);
        JMenuItem openItem = new JMenuItem("add");
        openItem.setFont(font);
        fileMenu.add(openItem);
         menuBar.add(textField2);
        JMenuItem closeItem = new JMenuItem("pop");
        closeItem.setFont(font);
        fileMenu.add(closeItem);
        JMenuItem printElem = new JMenuItem("print");
        printElem.setFont(font);
        fileMenu.add(printElem);
        JMenuItem closeEl = new JMenuItem("popel");
        closeEl.setFont(font);
        fileMenu.add(closeEl);
        fileMenu.addSeparator();

        JMenuItem exitItem = new JMenuItem("Exit");
        exitItem.setFont(font);
        fileMenu.add(exitItem);

        menuBar.add(fileMenu);
        exitItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });
        closeItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                  ml.delEl(textField2.getText());

            }
        });
          closeEl.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {

                     ml.popEl();

              }
          });

         openItem.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {

                   ml.add(textField2.getText());


             }
         });

         printElem.addActionListener(new ActionListener() {          public void actionPerformed(ActionEvent e) {

                 ml.printList(textField1);


             }
         });
        frame.setJMenuBar(menuBar);

        frame.setPreferredSize(new Dimension(270, 225));
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}
